package com.dmall.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Leetcode1V2 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int minus = target - nums[i];
            if (map.containsKey(minus)) {
                int[] res = new int[2];
                res[0] = map.get(minus);
                res[1] = i;
                return res;
            }
            map.put(nums[i], i);
        }

        return null;
    }

    public static void main(String[] args) {
        // int[] nums = {0, 4, 3, 0};
//        int[] nums = {-1, -2, -3, -4, -5};
        int[] nums = {3, 3};
        Leetcode1V2 leetcode1 = new Leetcode1V2();
        Arrays.stream(leetcode1.twoSum(nums, 6)).forEach(System.out::println);
    }
}
